// pages/evaluate/index.js
const handler = require("../../utils/function.js");
const { $Message } = require('../../dist/base/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current_num:5,
    current_eva: '非常好',
    active:'http://xyds.4hl.cn/xyds/uploads/otherimg/index/large-star.png',
    un_active:'http://xyds.4hl.cn/xyds/uploads/otherimg/index/large-star-active.png',
    evalute_language:["非常差",'差','一般','好','非常好'],
    star: ['http://xyds.4hl.cn/xyds/uploads/otherimg/index/large-star.png', 'http://xyds.4hl.cn/xyds/uploads/otherimg/index/large-star.png', 'http://xyds.4hl.cn/xyds/uploads/otherimg/index/large-star.png', 'http://xyds.4hl.cn/xyds/uploads/otherimg/index/large-star.png', 'http://xyds.4hl.cn/xyds/uploads/otherimg/index/large-star.png'],
    countent:'',
    tid:'',
    content:'',
    oid:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    var oid = options.oid;
    this.setData({tid:id,oid:oid})
    this.initData(id);
  },
  initData:function(id){
    var para = {
      id:id
    };
    var that = this;
    handler.requestData("getUserInfoById", para, function (res) {
      
      if (res.success == true) {
          that.setData({
            avatar:res.data.avatar,
            nick_name:res.data.nick_name,
            comment_count: res.data.comment_tearch_list.length,
            level_score: res.data.level_score
          })
      } else {
        wx.showToast({
          title: res.message,
          icon: 'loading'
        })
      }
    });
  },
  star_handler:function(e){
    // console.log(e.currentTarget.dataset.index);
    var startCount = e.currentTarget.dataset.index+1;
    // console.log(startCount);
    this.setData({
      current_num: startCount
   
    })
    var { active, un_active, evalute_language}=this.data;
    var star_num=[];
    var index = e.currentTarget.dataset.index+1;
    for(var i=0;i<5;i++){
      if (i < index){
        star_num[i] = active
      }else{
        star_num[i] = un_active
      }
    }
    this.setData({ star: star_num, current_num: index, current_eva: evalute_language[index-1]});
    // console.log(star_num);
  },
  commentContent:function(e){
    // console.log(e.detail.value)
    var content = e.detail.value;
    this.setData({
      content: content
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  get_information:function(){
    var current_num = this.data.current_num;
    var content = this.data.content;
    console.log(current_num, content,"11111111111111111111");
    var submitJson = {
      comment_user_id:wx.getStorageSync('user_info').id,
      user_id :this.data.tid,
      content: content,
      score: current_num,
      oid: this.data.oid
    };
    var that = this;
    handler.requestData("userComment", submitJson, function (res) {
      if (res.success == true) {
        wx.showToast({
          title: '评价成功',
        })
        handler.intoPageHandler("../index/index")
      } else {
        wx.showToast({
          title: res.message,
          icon:'loading'
        })
      }
    });
    // handler.intoPageHandler("../index/index")
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})